package com.itheima.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.ClazzMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Override
    public boolean saveStudent(Student student) {
        student.setViolationCount((short)0);
        student.setViolationScore((short)0);
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        return this.save( student);
    }

    @Override
    public boolean updateStudent(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        return this.updateById( student);
    }

    @Override
    public boolean violation(Integer id, Integer score) {
        //根据id查询
        Student student = this.getById(id);
        if (student!=null){
            student.setViolationCount((short) (student.getViolationCount()+1));
            student.setViolationScore((short) (student.getViolationScore()+score));
            student.setUpdateTime(LocalDateTime.now());
        }
        return this.updateById( student);
    }
}
